import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';

// ignore: must_be_immutable
class BottomNavigationBarPage extends StatefulWidget {
  String name;
  BottomNavigationBarPage({
    Key? key,
    required this.name,
  }) : super(key: key);

  @override
  _BottomNavigationBarPageState createState() =>
      _BottomNavigationBarPageState();
}

class _BottomNavigationBarPageState extends State<BottomNavigationBarPage> {
  int _currentIndex = 0;
  List<String> list = ['explore', 'history', 'person', 'list'];

  void handleTapHandler(int index) {
    // ignore: avoid_print
    print(index);
    // ignore: avoid_print
    print('index');
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
        body: Center(
          child: Text(
            list[_currentIndex],
            textDirection: TextDirection.rtl,
            style: TextStyle(
                fontSize: 30.0,
                fontWeight: FontWeight.bold,
                color: Theme.of(context).primaryColor),
          ),
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: handleTapHandler,
          type: BottomNavigationBarType.fixed, // 当tabBar个数大于等于四个
          fixedColor: Theme.of(context).primaryColor, // 激活背景颜色
          // ignore: prefer_const_literals_to_create_immutables
          items: [
            const BottomNavigationBarItem(
                icon: Icon(Icons.explore), label: 'explore'),
            const BottomNavigationBarItem(
                icon: Icon(Icons.history), label: 'history'),
            const BottomNavigationBarItem(
                icon: Icon(Icons.person), label: 'person'),
            const BottomNavigationBarItem(
                icon: Icon(Icons.list), label: 'list'),
          ],
        ));
  }
}
